﻿using MiniFox.Components;
using MiniFox.Infrastructure;
using MiniFox.Platform.Applications;
using MiniFox.Platform.Applications.Auth;
using MiniFox.Platform.Exceptions;
using Repository.Core.Models.Dto;
using Repository.Core.Models.Queries;
using Repository.Core.Models.VO;
using Repository.Core.Providers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Repository.Core.Services.Impls
{
    [AutoResolve]
    public class RepositoryService : Component, IRepositoryService
    {
        [AutoWired]
        protected IRepositoryProvider Provider {  get; set; }

        public ResultObject<IEnumerable<RepositorySetVo>> Query(PagedQueryObject<CommonQuery> request)
        {
            ResultObject<IEnumerable<RepositorySetVo>> result = Provider.Query(request);
            return result;
        }

        public RepositorySetVo Item(string name)
        {
            return this.Provider.GetItem(name);
        }

        public RepositorySetVo Save(RepositorySetDto dto)
        {
            if (!this.Provider.Save(dto))
                throw new PlatformException("ERR_OperateFail");

            return Item(dto.Name);
        }
    }
}
